//package com.summer.project.system.shoyo.service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.google.common.collect.Lists;
//import com.summer.project.system.shoyo.domain.Good;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.methods.HttpGet;
//import org.apache.http.util.EntityUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//
//import java.text.DateFormat;
//import java.text.SimpleDateFormat;
//import java.util.List;
//import java.util.Objects;
//
//public class Bak {
//    private static final Logger log = LoggerFactory.getLogger(ShoyoServiceImpl.class);
//
//    private String shoyoDailyPath;
//    private String yujianDailyPath;
//
//    private String shoyoTokenPath;
//    private String yujianTokenPath;
//
//    private String receiveMail;
//
//    private DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
//    private DateFormat df2 = new SimpleDateFormat("yyyy年MM月dd日");
//
//    private String baseUrl = "https://bk.jbzyun.cn/micro/minipage?type=wpage&siteId={siteId}&limitNum=10&id=&storeId=&customPage=&middleId=&middlePageId=&version=0523";
//
//    private String baseChildUrl = "https://bk.jbzyun.cn/micro/minipage?type=wpage&siteId={siteId}&limitNum=10&id={id}&storeId=&customPage=&middleId=&middlePageId=&version=0523";
//
//    private String generateUrl = "https://bk.jbzyun.cn/micro/mall-extend/goods/generate-poster";
//
//    private List<Good> getGoodList(String page, String token, String siteId) throws Exception {
//        String childPageUrl = baseChildUrl.replace("{siteId}", siteId);
//        HttpGet get = new HttpGet(page);
//        get.setHeader("Access-Control-Allow-Origin", "https://h5.jbzyun.cn");
//        get.setHeader("X-C3-Agentid", "168654126");
//        get.setHeader("X-C3-Token", token);
//        get.setHeader("X-Client-Type", "h5");
//        List<Good> goodList = Lists.newArrayList();
//        List<Integer> childPageIds = Lists.newArrayList();
//        HttpResponse response = httpClient.execute(get);
//        if (response != null && response.getEntity() != null) {
//            String result = EntityUtils.toString(response.getEntity(), "UTf-8");
//            JSONObject json = JSON.parseObject(result);
//            JSONObject body = json.getJSONObject("body");
//            JSONObject htmlPage = body.getJSONObject("htmlPage");
//            String htmlBody = htmlPage.getString("htmlBody");
//            JSONArray htmlBodys = JSON.parseArray(htmlBody);
//            for (Object o : htmlBodys) {
//                JSONObject html = (JSONObject) o;
//                if (Objects.equals(html.getString("size"), "0")) {
//                    if (Objects.equals(html.getString("name"), "goods")) {
//                        JSONArray goodArray = html.getJSONArray("goods");
//                        for (Object obj : goodArray) {
//                            Good good = JSON.toJavaObject(((JSONObject) obj), Good.class);
//                            goodList.add(good);
//                        }
//                    }
//                }
//                JSONArray imageList = html.getJSONArray("imageList");
//                if (imageList != null && imageList.size() > 0) {
//                    imageList.forEach(i -> {
//                        JSONObject image = (JSONObject) i;
//                        JSONArray hotAreas = image.getJSONArray("hotAreas");
//                        if (hotAreas != null) {
//                            hotAreas.forEach(h -> {
//                                JSONObject hotArea = (JSONObject) h;
//                                JSONObject linkUrl = hotArea.getJSONObject("linkUrl");
//                                if (Objects.equals("100", hotArea.getString("widthRate")) && !Objects.equals(linkUrl.getString("title"), "轻氧专区")) {
//                                    childPageIds.add(linkUrl.getIntValue("id"));
//                                }
//                            });
//                        }
//                    });
//                }
//
//            }
//        }
//        if (!childPageIds.isEmpty()) {
//            for (Integer id : childPageIds) {
//                goodList.addAll(getGoodList(childPageUrl.replace("{id}", String.valueOf(id)), token, siteId));
//            }
//        }
//        return goodList;
//    }
//
//}
